﻿


<div ms-controller="tempview">
    <div class="sui-form form-inline">
        <a class="sui-btn btn-large btn-success" style="margin-left:10px;" ms-click="GetLIST()">刷新楼层</a>
        <a style="margin-left:10px;" class="sui-btn btn-large btn-primary" ms-click="ADD('')">添加楼层</a>
    </div>
    <div class="sui-layout">
        <div class="sidebar">
            <p style="border-bottom: 2px solid #28a3ef;padding-bottom:10px;margin-top:0">所有楼层</p>
            <ul id="treeDemo" class="ztree"></ul>
        </div>
        <div class="content sui-form form-horizontal" ms-visible="IsShow">
            <div ms-visible="IsLayc">

                <p style="border-bottom: 2px solid #28a3ef;padding-bottom:10px;">设备属性
                    <a style="float:right;margin-left:10px;" href="javascript:void(0)" class="btn btn-success btn-large" ms-click="UpdateFresh()">刷新设备信息</a>
                <a style="float:right;" href="javascript:void(0)" class="btn btn-primary btn-large" ms-click="UpdateLayc()">保存</a>
                </p>
                <!--<div class="control-group">
                    <label class="control-label">设备名称：</label>
                    <div class="controls">
                        <input class="input-xlarge input-xfat" type='text' ms-duplex="modelData.EquName" />
                    </div>
                </div>-->
                <div class="control-group">
                    <label class="control-label">设备IP：</label>
                    <div class="controls">
                        <input class="input-medium input-xfat" type='text' ms-duplex="modelData.IP" />
                        端口号：
                        <input class="input-medium input-xfat" type='text' ms-duplex="modelData.Port" />
                        设备地址：
                        <input class="input-medium input-xfat" type='text' ms-duplex="modelData.EquAD" />
                        <span style="color:red;">两位,比如01</span>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">设备名称：</label>
                    <div class="controls">
                        <input class="input-xlarge input-xfat" type='text' ms-duplex="modelData.EquName" maxlength="15" />
                        <span style="color:red;">最多15个字</span>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">安装位置：</label>
                    <div class="controls">
                        <input class="input-xlarge input-xfat" type='text' ms-duplex="modelData.SetupAD" maxlength="10" />
                        <span style="color:red;">最多10个字</span>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">版本号：</label>
                    <div class="controls">
                        <label>{{modelData.EquVersion}}</label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">设备型号：</label>
                    <div class="controls">
                        <label>{{modelData.EquModel}}</label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">最大通道数：</label>
                    <div class="controls">
                        <label>{{modelData.MaxPath}}</label>
                    </div>
                </div>
                <!--<div class="control-group">
                    <label class="control-label">系统时间：</label>
                    <div class="controls">
                        <label>{{modelData.EquTime}}</label>
                    </div>
                </div>-->
                <div class="control-group">
                    <label class="control-label">设备波特率：</label>
                    <div class="controls">
                        <label>{{modelData.EquBit}}</label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">节电模式：</label>
                    <div class="controls">
                        <label>{{modelData.EquPower}}</label>
                    </div>
                </div>
                <!--<div class="control-group">
                    <label class="control-label">告警延迟(s)：</label>
                    <div class="controls">
                        <label>{{modelData.EquWaring}}</label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">故障延迟(s)：</label>
                    <div class="controls">
                        <label>{{modelData.EquError}}</label>
                    </div>
                </div>-->
            </div>
            <div ms-visible="!IsLayc">

                <p style="border-bottom: 2px solid #28a3ef;padding-bottom:10px;">通道属性<!--<a style="float:right;" href="javascript:void(0)" class="btn btn-primary btn-large" ms-click="UPDATEPATH()">保存</a>--></p>

                <div class="control-group">
                    <label class="control-label">通道名称：</label>
                    <div class="controls">
                        <!--<input class="input-xlarge input-xfat" type='text' ms-duplex="modelData2.PathName" />-->
                        <label>{{modelData2.PathName}}</label>
                    </div>
                </div>

                <div class="control-group">
                    <label class="control-label">通道类型：</label>
                    <div class="controls">
                        <label>{{modelData2.PathType}}</label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">单位：</label>
                    <div class="controls">
                        <label>{{modelData2.PathUnit}}</label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">小数位：</label>
                    <div class="controls">
                        <label>{{modelData2.PathDecimal}}</label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">量程：</label>
                    <div class="controls">
                        <label>{{modelData2.PathValue}}</label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">偏移量：</label>
                    <div class="controls">
                        <label>{{modelData2.PathDiff}}</label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">低限阀值：</label>
                    <div class="controls">
                        <label>{{modelData2.PathMin}}</label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">高限阀值：</label>
                    <div class="controls">
                        <label>{{modelData2.PathMax}}</label>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<script type="text/javascript">

    var treeObj;
    var tempmodel = avalon.define({
        $id: "tempview",
        search: { key: "" },
        page: { pageindex: 1, pagecount: 10 },
        modelData: {},
        modelData2: {},
        ShowColumns: [],
        ListData: [],
        APINAME: "",
        Operation: "",
        IsLayc: true,
        IsShow:false,
        GetLIST: function () {

            ComFunJS.getJSON("BASE_GETLAYCTREE", { P2: 1 }, function (r) {
                if (r.error == "") {
                    tempmodel.ListData = r.result;

                    var setting = {
                        edit: {
                            enable: true,
                            //editNameSelectAll: true,
                            showRemoveBtn: showRemoveBtn,
                            showRenameBtn: showRenameBtn
                        },
                        callback: {
                            beforeRemove: beforeRemove,
                            onClick: zTreeOnClick
                        }
                    };
                    var zNodes = eval("(" + JSON.stringify(r.result) + ")");

                    treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);

                }
            })
        },
        DEL: function (el) {
            ComFunJS.winShowConfirm("确认删除吗", function () {
                ComFunJS.getJSON("BASE_DELLAYC", { P1: el.ID }, function (r) {
                    tempmodel.ListData.remove(el);
                })
            })

        },
        ADDLAYC: function () {

            ComFunJS.winShowFormBtn("添加大楼", "/admin/ADD/LOU.html", "500", "400", function (layero, index) {
                var body = layer.getChildFrame('body', index);
                var txtLouNo = body.find("#txtLouNo").val();
                var txtLouNum = body.find("#txtLouNum").val();
                if(txtLouNo&&txtLouNum)
                {
                    ComFunJS.postJSON("BASE_ADDLOU", { "P1": txtLouNo, "P2": txtLouNum }, function (r) {
                        if (r.error == "") {
                            ComFunJS.winShowMsg("添加成功");
                        } else {
                            ComFunJS.winShowMsg(r.error);
                        }
                    })


                    layer.close(index);
                }

              

            })
            //ComFunJS.winShowPrompt("请输入最高楼层", function (result) {

            //    ComFunJS.getJSON("BASE_ADDLAYC", { P1: result }, function (r) {
            //        if (r.error == "") {
            //            tempmodel.GetLIST();
            //        }
            //    })

            //})
        },
        UpdateLayc: function () {
            if (tempmodel.modelData) {
                ComFunJS.postJSON("BASE_UPDATELAYC", { P1: JSON.stringify(tempmodel.modelData.$model) }, function (r) {
                    if (r.error == "") {

                        top.ComFunJS.winShowMsg("操作成功");
                    } else {
                        top.ComFunJS.winShowAlert(r.error);
                    }

                })
            }
        },
        GetEqu: function (ID, lvl) {
            if (lvl == "2") {
                tempmodel.IsLayc = true;
                ComFunJS.getJSON("BASE_GETLAYCMODEL", { P1: ID }, function (r) {
                    if (r.error == "") {
                        tempmodel.modelData = r.result;

                    }

                });
            } else if(lvl=="3") {
                tempmodel.IsLayc = false;
                ComFunJS.getJSON("BASE_GETPATHMODEL", { P1: ID }, function (r) {
                    if (r.error == "") {
                        tempmodel.modelData2 = r.result;
                    }

                });
            }

        },
        UPDATEPATH: function () {
            if (tempmodel.modelData2) {
                ComFunJS.postJSON("BASE_UPDATEPATH", { P1: JSON.stringify(tempmodel.modelData2.$model) }, function (r) {
                    if (r.error == "") {
                        var nodes = treeObj.getSelectedNodes();
                        nodes[0].name = tempmodel.modelData2.PathName;
                        treeObj.updateNode(nodes[0]);
                        top.ComFunJS.winShowMsg("操作成功");
                    } else {
                        top.ComFunJS.winShowAlert(r.error);
                    }

                });
            }

        },
        UpdateFresh: function () {

            if (tempmodel.modelData) {
                ComFunJS.postJSON("BASE_FRESHLAYER", { P1: tempmodel.modelData.ID }, function (r) {
                    if (r.error == "") {

                        top.ComFunJS.winShowMsg("操作成功");
                    } else {
                        top.ComFunJS.winShowAlert(r.error);
                    }

                })
            }

        }
    })
    avalon.ready(function () {

        tempmodel.GetLIST();
        //$(".sidebar").height(window.outerHeight - 100);
    })

    function zTreeOnClick(event, treeId, treeNode) {
        tempmodel.IsShow = true;
        tempmodel.GetEqu(treeNode.ID, treeNode.lvl);

    };
    function showRemoveBtn(treeId, treeNode) {
        return treeNode.lvl != 3;
    }
    function showRenameBtn(treeId, treeNode) {
        return false;
    }
    function beforeRemove(treeId, treeNode) {

        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.selectNode(treeNode);

        var desp = "确认删除" + treeNode.name + "吗?";

        top.ComFunJS.showConfirm(desp, function () {
            ComFunJS.postJSON("BASE_DELLAYC", { P1: treeNode.ID, P2: treeNode.lvl }, function (r) {
                if (r.error == "") {
                    zTree.removeNode(treeNode)
                    top.ComFunJS.winShowMsg("操作成功");
                } else {
                    top.ComFunJS.winShowAlert(r.error);
                }

            })
            

        })
        return false;
    }

    //# sourceURL=layc.js
</script>
